package com.lul15834.orderfood.activity.user;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.bean.AddressBean;
import com.lul15834.orderfood.dao.AddressDao;
import com.lul15834.orderfood.until.Tools;

public class AddUserAddress extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_add_user_address);
        //加载上个界面传过来的数据
        Toolbar toolbar=findViewById(R.id.user_add_address_back);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(AddUserAddress.this,UserAddress.class);
                startActivity(intent);
            }
        });
        String id= Tools.getOnAccount(this);
        EditText name1=findViewById(R.id.user_add_address_name);
        EditText address1=findViewById(R.id.user_add_address);
        EditText phone1=findViewById(R.id.user_add_address_phone);
        Button btn=findViewById(R.id.user_add_address_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=name1.getText().toString();
                String address=address1.getText().toString();
                String phone=phone1.getText().toString();
                if (name.isEmpty()){
                    Toast.makeText(AddUserAddress.this, "请输入收货人昵称", Toast.LENGTH_SHORT).show();
                }else if (address.isEmpty()){
                    Toast.makeText(AddUserAddress.this, "请输入收货人地址", Toast.LENGTH_SHORT).show();
                }else if ((phone.isEmpty())){
                    Toast.makeText(AddUserAddress.this, "请输入收货人联系方式", Toast.LENGTH_SHORT).show();
                }else{
                    int a= AddressDao.addAddress(id,name,address,phone);
                    if (a==1){
                        Toast.makeText(AddUserAddress.this, "更改成功", Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(AddUserAddress.this, "更改失败", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
    }

}